﻿using FreeSql.DataAnnotations;

IFreeSql fsql = new FreeSql.FreeSqlBuilder()
 .UseConnectionString(FreeSql.DataType.KingbaseES, @"Server=127.0.0.1;Port=54321;UID=USER2;PWD=123456789;database=TEST;MAXPOOLSIZE=2")
 .UseAutoSyncStructure(true) //automatically synchronize the entity structure to the database
 .Build(); //be sure to define as singleton mode

fsql.Select<Tag>().Where(a => a.Parent.Parent.Name == "English").ToList();

Console.WriteLine("执行完成");

internal class Song
{
    [Column(IsIdentity = true)]
    public int Id { get; set; }

    public string Title { get; set; }
    public string Url { get; set; }
    public DateTime CreateTime { get; set; }

    public ICollection<Tag> Tags { get; set; }
}

internal class Song_tag
{
    public int Song_id { get; set; }
    public Song Song { get; set; }

    public int Tag_id { get; set; }
    public Tag Tag { get; set; }
}

internal class Tag
{
    [Column(IsIdentity = true)]
    public int Id { get; set; }

    public string Name { get; set; }

    public int? Parent_id { get; set; }
    public Tag Parent { get; set; }

    public ICollection<Song> Songs { get; set; }
    public ICollection<Tag> Tags { get; set; }
}